# -*- coding: utf-8 -*-
# author: AZJ
# date: 2024/11/9
# 假如命运扼住了你的咽喉，你就去挠她的咯吱窝
class Solution(object):
    def rob(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        # dp[i] 偷窃第 i 个房屋的金额总和
        # dp[0] = nums[0]
        # dp[1] = max(nums[0], num[1])
        # dp[i] = max(dp[i-1], dp[i-2] + nums[i])
        n = len(nums)
        dp = [0] * n
        dp[0] = nums[0]
        dp[1] = max(nums[0], nums[1])
        for i in range(2, len(nums)):
            dp[i] = max(dp[i-1], dp[i-2] + nums[i])
        return dp[n-1]
if __name__ == '__main__':
    print(Solution().rob([2,7,9,3,1]))